package com.weim.config;

import com.weim.utils.CommonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.net.HttpURLConnection;
import java.net.URL;

/**
 * 启动之后  首先获取一个 cookie
 * @author weim
 * @date 18-8-20
 */

@Component
public class MyApplication implements ApplicationRunner {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public void run(ApplicationArguments args) throws Exception {
//        URL url = new URL("http://www.biquge.com.tw/");
//        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//        connection.setRequestMethod("GET");
//        connection.setConnectTimeout(5000);
//
//        if(connection.getResponseCode() == 521) {
//            String setCookie = connection.getHeaderField("Set-Cookie");
//            CommonUtils.cookie = setCookie.substring(0,setCookie.indexOf(";"));
//        }

        logger.info("cookie==>" + CommonUtils.cookie);

    }
}
